#include <buola/cv/features/cfeatureview.h>
#include <buola/image/cgc.h>

namespace buola { namespace cvi {
    
CFeatureView::CFeatureView()
{
    
}

CFeatureView::~CFeatureView()
{
    
}

void CFeatureView::OnExpose(const gui::CExposeEvent &pE)
{
    CImageBox::OnExpose(pE);

    if(!mFeatureSet) return;
    
    if(mIndex>=0&&mIndex<mFeatureSet.size())
    {
        pE.mGC->SetSource(img::CColor(0,1,0));
        pE.mGC->SetLineWidth(3.0);
        
        const cvi::CKeyPoint &lKP=mFeatureSet[mIndex];
        pE.mGC->Path().Arc(lKP.Point(),lKP.Size()/2);
        pE.mGC->StrokePath();
    }
}

void CFeatureView::OnKeyDown(const gui::CKeyEvent &pE)
{
    if(pE.mKey==KEY_RIGHT)
    {
        if(mFeatureSet&&mIndex<mFeatureSet.size())
        {
            mIndex++;
            Refresh();
        }
    }
    else if(pE.mKey==KEY_LEFT)
    {
        if(mFeatureSet&&mIndex>0)
        {
            mIndex--;
            Refresh();
        }
    }
}

void CFeatureView::SetFeatures(CFeatureSet &&pSet)
{
    mFeatureSet=std::move(pSet);
    mIndex=0;
}

void CFeatureView::SelectFeature(int pIndex)
{
    mIndex=pIndex;
    Refresh();
}
    
/*namespace cvi*/ } /*namespace buola*/ }